﻿using System;
using NetBay.Core.BusinessEntities;
using Rio.Flow.Business.Repository;
using Rio.Framework.RioManager;
using Rio.Workflow.Runtime;
using NetBay.Core.BusinessEntities.Workflow;

namespace Rio.Workflow.Mailing
{
    public sealed class Outboxing : WorkflowContext
    {

        #region Properties

        /// <summary>
        /// Gets the type of the WKF.
        /// </summary>
        /// <value>The type of the WKF.</value>
        public override WorkflowType WkfType
        {
            get { return WorkflowType.Outboxing; }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Outboxing" /> class.
        /// </summary>
        public Outboxing()
        {
            this.WorkflowFaulted += new Runtime.Events.WorkflowEventHandler(Outboxing_WorkflowFaulted); 
            this.WorkflowStarted += new Runtime.Events.WorkflowEventHandler(Outboxing_WorkflowStarted);
            this.AfterExecuteAction += new Runtime.Events.WorkflowEventHandler(Outboxing_AfterExecuteAction);
            this.BeforeExecuteAction += new Runtime.Events.WorkflowEventHandler(Outboxing_BeforeExecuteAction);
        }

        #endregion

        #region Events Handlers

        private void Outboxing_WorkflowFaulted(object sender, Runtime.Events.WorkflowEventArgs args)
        {
        }

        private void Outboxing_WorkflowStarted(object sender, Runtime.Events.WorkflowEventArgs args)
        {
        }

        private void Outboxing_BeforeExecuteAction(object sender, Runtime.Events.WorkflowEventArgs args)
        {
        }

        private void Outboxing_AfterExecuteAction(object sender, Runtime.Events.WorkflowEventArgs args)
        {
        }

        #endregion

        /// <summary>
        /// Generates the chrono.
        /// </summary>
        /// <param name="request"></param>
        /// <returns>The newest chrono item.</returns>
        public override Item RequestChrono(ChronoRequest request)
        {
            Item result = new Item(0, "");

            if (request.InputedFlowTypeValue.Equals("Papier", StringComparison.CurrentCultureIgnoreCase))
            {
                Tuple<long, string> l_oReturnTuple = MessageFlowRepository.GenerateChrono(2, SettingsManager.cStoreSettings.Parameter_ChronoPrefix, 2, request.UserId);
                result = new Item(l_oReturnTuple.Item1, l_oReturnTuple.Item2);
            }
            return result;
        }
    }
}
